﻿using Moven.Controls;
using Moven.ViewModels;
using Xamarin.Forms;

namespace Moven.Views
{
	public class SearchResultCell:
	#if __ANDROID__
	TextCell
	#elif __IOS__
	BaseArticleCell
	#endif
	{
#if __IOS__
		Label _label;
#endif

#if __ANDROID__
		public ArticleWithBookmark Article => BindingContext as ArticleWithBookmark;
#endif

		public SearchResultCell()
		{
#if __ANDROID__
			TextColor = Color.Black;
#elif __IOS__
			var container = new QuickStackLayout
			{
				Padding = new Thickness(16, 8)
			};

			_label = new Label
			{
				LineBreakMode = LineBreakMode.TailTruncation,
				TextColor = Color.Black
			};

			var separator = new BoxView
			{
				Color = Statics.SeparatorColor,
				HeightRequest = 0.5,
				Margin = new Thickness(0, 0, 0, -8)
			};

			container.Children.Add(_label);
			container.Children.Add(separator);
			View = container;
#endif
		}

		protected override void OnBindingContextChanged()
		{
			var article = Article;
			if (article != null)
			{
#if __ANDROID__
				Text = article.Title;
#elif __IOS__
				_label.Text = article.Title;
#endif
			}

			base.OnBindingContextChanged();
		}
	}
}
